const mongoose = require('mongoose')

const schema = new mongoose.Schema({
    account: {
        type: String
    },
    password: {
        type: String,
        required: true,
        set(val){
            // 进行散列加密
            return require('bcrypt').hashSync(val, 10)
        },
        select: false
    },
    //虚拟名称
    name: {
        type: String,
        required: true
    },
    phone: {
        type: String,
        required: true
    },
    //车位号
    carNumber: {
        type: String
    },
    //所属小区
    parentCell: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: 'Cell'
    },
    //所属的楼
    parentFloor: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: 'Floor'
    },
    room: {
        type: String,
        required: true
    },
    //角色权限分类
    user_type: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: 'UserType'
    }
},{
    timestamps: true
})

module.exports = mongoose.model('User', schema)